package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.PastOrPresent;
import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级")
public class NursingLevelController {

      @Autowired
    private NursingLevelService nursingLevelService;

      @GetMapping("/listAll")
      @ApiOperation(value = "查询所有护理等级")
      public ResponseResult listAll(){
          List<NursingLevelVo> nursingLevels = nursingLevelService.listAll();
           return ResponseResult.success(nursingLevels);
      }

      //新增
      @PostMapping("/insert")
      @ApiOperation(value = "新增护理等级")
      public ResponseResult insert(@RequestBody NursingLevelDto nursingLevelDto){
          nursingLevelService.insert(nursingLevelDto);
          return ResponseResult.success();
      }
     //条件分页查询
     @GetMapping("/listByPage")
      @ApiOperation(value = "条件分页查询护理等级")
      public ResponseResult<PageResponse<NursingLevelVo>> getNursingLevel(
             @ApiParam(value = "护理等级名称") String name,
             @ApiParam(value = "当前页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
             @ApiParam(value = "每页展示条数") @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
             @ApiParam(value = "护理等级状态") Integer status
     ) {

         PageResponse<NursingLevelVo>  NursingLevelVoPageResponse = nursingLevelService.getNursingLevel(name, pageNum, pageSize, status);
          return ResponseResult.success(NursingLevelVoPageResponse);
     }
    //根据id查询
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理等级")
    public ResponseResult<NursingLevelVo> getNursingLevelById(@PathVariable() @ApiParam(value = "护理等级id") Long id){
        NursingLevelVo nursingLevelVo = nursingLevelService.getNursingLevelById(id);
        return ResponseResult.success(nursingLevelVo);
    }
    //修改
    @PutMapping("/update")
    @ApiOperation(value = "修改护理等级")
    public ResponseResult updateNursingLevel(@RequestBody  NursingLevelDto nursingLevelDto){
        nursingLevelService.updateNursingLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    //删除
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除护理等级")
    public ResponseResult deleteNursingLevel(@PathVariable() @ApiParam(value = "护理等级id") Long id){
        nursingLevelService.deleteNursingLevel(id);
        return ResponseResult.success();
    }
    // 启用禁用
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用禁用护理等级")
    public ResponseResult updateStatus(@PathVariable() @ApiParam(value = "护理等级id") Long id
            , @PathVariable() @ApiParam(value = "状态") Integer status) {
        nursingLevelService.updateStatus(id, status);
        return ResponseResult.success();
    }
}
